#define  _CRT_SECURE_NO_WARNINGS
#include <vector>
using namespace std;

class Solution {
public:
    bool findTargetIn2DPlants(vector<vector<int>>& plants, int target) {
        if (plants.size() == 0) return false;
        int m = plants.size(), n = plants[0].size();
       
        for (int i = 0, j = n - 1; i < m && j >= 0;)
        {
            if (plants[i][j] == target)
                return true;
            else if (plants[i][j] > target)
                j--;
            else if (plants[i][j] < target)
                i++;
        }
        return false;
    }
};


class Solution {
public:
    bool findTargetIn2DPlants(vector<vector<int>>& plants, int target) {
        if (plants.size() == 0) return false;
        int m = plants.size(), n = plants[0].size();

        for (int i = m - 1, j = 0; j < n && i >= 0;)
        {
            if (plants[i][j] == target)
                return true;
            else if (plants[i][j] > target)
                i--;
            else if (plants[i][j] < target)
                j++;
        }
        return false;
    }
};